/*
 * Server.cpp
 *
 *  Created on: 19.11.2013
 *      Author: ulgish
 */

#include "lab5/server/Server.h"
#include <string.h>

Server::Server(const std::string & channelName)
{
	srv = name_attach(NULL, channelName.c_str(), 0);
	DT::writer << "Server created.\n";
}

void Server::start(){
	DT::writer << "Server started:\n";
	while(1){
		int recvid = MsgReceive(srv->chid, buf, 1024,NULL);
		DT::writer << "Server receive message from :" << recvid << "\n";
		if (recvid == 0){
			break;
		}
		DT::writer << "Message:" << buf << "\n";
		if (strcmp(buf, "exit") == 0){
			break;
		}
		MsgReply(recvid, 0, NULL,0);
	}
	return;
}

Server::~Server() {
	// TODO Auto-generated destructor stub
	name_detach(srv, 0);
}
